package com.alliky.core.base

import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import com.alibaba.android.arouter.launcher.ARouter
import com.alliky.common.api.BaseApi
import com.alliky.common.global.Global
import com.alliky.core.config.AppConfig
import com.alliky.core.config.ModuleLifecycleConfig
import com.scwang.smartrefresh.header.WaterDropHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.api.DefaultRefreshInitializer
import com.scwang.smartrefresh.layout.footer.ClassicsFooter

open class BaseApplication : MultiDexApplication() {

    companion object {

    }

    override fun onCreate() {
        super.onCreate()

        MultiDex.install(this)

        //初始化组件(靠前)
        ModuleLifecycleConfig.instance.initModuleAhead(this)

        //初始化组件(靠后)
        ModuleLifecycleConfig.instance.initModuleLow(this)

        ARouter.init(this)
        ARouter.openLog() // 打印日志
        ARouter.openDebug()

        AppConfig.init(this)
            .withLoaderDelayed(500)
            .withApiHost(BaseApi.API_HOST)
            .withWeChatAppId(Global.ThirdPlatform.WECHAT_APP_ID)
            .withWeChatAppSecret(Global.ThirdPlatform.WECHAT_APP_SECRET)
            .configure()

        SmartRefreshLayout.setDefaultRefreshInitializer { context, layout ->
            layout.setRefreshHeader(WaterDropHeader(context))
            layout.setRefreshFooter(ClassicsFooter(context))
        }
    }
}